<script>
import store from '@/store'

export default {
  data() {
    return {
      id: '',
    }
  },
  onLaunch: function (options) {
    this.id = options.query.invite || ''
    this.initApp()
  },
  methods: {
    initApp() {
      // store.dispatch('getSetting')
      // store.dispatch('setRoleList')

      if (uni.getStorageSync('token') && uni.getStorageSync('userInfo')) {
        store.commit('setToken', uni.getStorageSync('token'))
        store.commit('setUserInfo', uni.getStorageSync('userInfo'))
        store.dispatch('getUserInfo')
        store.commit('initHistoryList')
      }

      // #ifdef H5
      this.initRoute()
      // #endif
      // #ifdef MP-WEIXIN
      this.initWx()
      // #endif
    },
    initRoute() {
      // if (!store.state.auth.token) {
      //   return uni.redirectTo({
      //     url: '/pages/login/index',
      //   })
      // }
      uni.redirectTo({
        url: '/pages/home/home',
      })
    },
    initWx() {
      if (!store.state.auth.token) {
        uni.login({
          provider: 'weixin',
          success: async (loginRes) => {
            console.log('登录信息', loginRes)
            await store.dispatch('wxLogin', {
              JsCode: loginRes.code.toString(),
              InvitationUID: +this.id || 0,
            })
            this.$store.dispatch('IuserSettingInfo')

            // const res = await getMobile({ code: loginRes.code.toString() })
            // console.log(res)
          },
        })
      }
    },
  },
  onHide: function () {},
}
</script>

<style lang="scss">
@import 'uview-ui/index.scss';
uni-page {
  background-color: rgba(246, 247, 249, 1);
}
page {
  background-color: rgba(246, 247, 249, 1);
}
.u-navbar__content__title {
  font-size: 36rpx !important;
  font-weight: 700 !important;
}
.uni-page-head .uni-page-head__title {
  font-size: 36rpx !important;
}
</style>
